package com.xtm.exercise.menu;

import com.xtm.common.controller.ResultController;
import com.xtm.common.model.Result;
import com.xtm.common.model.SysMenu;
import com.xtm.exercise.menu.base.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单模块 - 控制层 - 用于演示 MyBatis 的使用<p/>
 */
@Slf4j
@ResultController
@RequiredArgsConstructor
@Api(value = "菜单模块", tags = "演示示例")
public class MenuController {

    private final IMenuService menuService;

    /**
     * 查询所有菜单
     */
    @GetMapping("/menus")
    @ApiOperation(value = "查询所有菜单")
    public List<SysMenu> findMenus () {
        return menuService.findAll();
    }

    /**
     * 新增菜单
     */
    @PostMapping("/menus")
    @ApiOperation(value = "新增菜单")
    public Result<?> addMenu (@RequestBody SysMenu menu) {
        menuService.addMenu(menu);
        return Result.ok("新增菜单成功");
    }

    /**
     * 删除菜单
     */
    @DeleteMapping("/menus/{id}")
    @ApiOperation(value = "删除菜单")
    public Result<?> delMenu (@PathVariable Long id) {
        menuService.delMenu(id);
        return Result.ok("删除菜单成功");
    }

}
